﻿using protoNet;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using UnityEngine;
using VitServer;

public class ContentNotice : MonoBehaviour {
    JFSocket _Socket;
    // Use this for initialization
    void Start () {
        //TODO..制作滚动公告栏
        _Socket = JFSocket.GetInstance();
        MsgReader.OnMessageRecieved(GAME_PROTOCOL_MSG_ID.ID_S2C_LOGIN_LOBBY, OnLobbyCallBack);
        
       
       
       
    }
	
	// Update is called once per frame
	void Update () {
		
	}

    public void Buttonaaaaqaaa()
    {
        SendID_C2S_LOGIN_LOBBY(SaveHallData.Instance.token, "192.168.0.2", SaveHallData.Instance.host);
    }

    public void SendID_C2S_LOGIN_LOBBY(string _token, string _ip, string host)
    {
        MsgLoginLobbyReq req = new MsgLoginLobbyReq()
        {
            token = _token,
            ip = _ip
        };
        Serialize sl = new Serialize(GAME_PROTOCOL_MSG_ID.ID_S2C_LOGIN_LOBBY, req);
        Debug.Log("555555555555555555555555" + sl.SerializedBuffer[3] + "   " + sl.SerializedBuffer[4]); 
        _Socket.SendMessage(sl.SerializedBuffer);
    }
    //private void Client(byte[] buff)
    //{
    //   // Socket socket = new Socket()
    //    TcpClient client = new TcpClient();
    //    try
    //    {
    //        client.Connect("192.168.0.254",1002);//同步方法，连接成功、抛出异常、服务器不存在等之前程序会被阻塞  
    //    }
    //    catch (Exception ex)
    //    {
    //        Debug.Log("客户端连接异常：" + ex.Message);
    //    }
    //    Debug.Log("LocalEndPoint = " + client.Client.LocalEndPoint + ". RemoteEndPoint = " + client.Client.RemoteEndPoint);

    //    //客户端发送数据部分  
    //    NetworkStream streamToServer = client.GetStream();//获得客户端的流  
    //    streamToServer.Write(buff,0,buff.Length);//将转换好的二进制数据写入流中并发送  
    //    Debug.Log("发出消息：" + buff);
    //    byte [] buttf = new byte[1024];
    //    streamToServer.Read(buttf, 0, buttf.Length);
    //    MsgReader.ReadMessage(buttf);
    //}

    void OnLobbyCallBack(object message)
    {
        var msg = (MsgLoginLobbyRep)message;
        _G.Print("OnLobbyCallBack");
        _G.Print("cardCount:" + msg.cardCount.ToString());
        _G.Print("ip:" + msg.ip);
        _G.Print("nickName:" + msg.nickName);
        _G.Print("reconnect:" + msg.reconnect);
        _G.Print("roomHost:" + msg.roomHost);
        _G.Print("roomId:" + msg.roomId);
        _G.Print("sex:" + msg.sex.ToString());
        _G.Print("total:" + msg.total.ToString());
        _G.Print("type:" + msg.type.ToString());
        _G.Print("uid:" + msg.uid.ToString());
        _G.Print("win:" + msg.win.ToString());
    }
}
